home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jeditmodes / exmh-mode.tcl < prev    next >
Encoding:
Text File  |  1995-02-09  |  4.6 KB  |  178 lines

  1. # exmh-mode.tcl - mode for composing mail in exmh
  2. #
  3. # To use this, set your editor in exmh to "jedit -mode exmh -for &"
  4. ######################################################################
  5.  
  6. proc mode:exmh:init { t } {
  7.   global JEDIT_MODEPREFS
  8.   
  9.   j:read_prefs -array JEDIT_MODEPREFS -prefix exmh \
  10.     -directory ~/.tk/jeditmodes -file mh-defaults {
  11.     {textfont default}
  12.     {textwidth 80}
  13.     {textheight 24}
  14.     {textwrap char}
  15.     {sabbrev 0}
  16.     {dabbrev 0}
  17.     {autobreak 1}
  18.     {autoindent 0}
  19.     {savestate 0}
  20.     {buttonbar 1}
  21.     {menu,editor 1}
  22.     {menu,file 1}
  23.     {menu,edit 1}
  24.     {menu,prefs 0}
  25.     {menu,abbrev 1}
  26.     {menu,filter 1}
  27.     {menu,format 0}
  28.     {menu,display 0}
  29.     {menu,mode1 1}
  30.     {menu,mode2 1}
  31.     {menu,user 1}
  32.   }
  33.   
  34.   # catch {$t tag configure header -background LemonChiffon}
  35.   $t tag configure header -relief flat        ;# just to create it
  36.   $t tag lower header
  37.   catch {$t tag configure sig -font {-*-courier-bold-r-normal--10-100-*}}
  38.   $t tag lower sig
  39.   
  40.   # problematical: gets in the way of dabbrevs
  41.   #
  42.   bind $t <Double-Tab> "mode:exmh:to_body $t"
  43.   bind $t <Tab> "mode:exmh:next_header $t"
  44. }
  45.  
  46. ######################################################################
  47. # special hooks:
  48.  
  49. proc mode:exmh:post_read_hook { filename t } {
  50.   set separator {}
  51.   if [regexp -indices "\n-*\n" [$t get 0.0 end] separator] {
  52.     set headerend [lindex $separator 0]
  53.     $t tag add header 0.0 "0.0 + $headerend chars + 1 char"
  54.   }
  55. }
  56.  
  57. proc mode:exmh:pre_quit_hook { t } {
  58.   global JEDIT_CALLER
  59.   set filename [jedit:get_filename $t]
  60.   set draft_id [file tail $filename]
  61.   send $JEDIT_CALLER "EditDialog $draft_id"
  62. }
  63.  
  64. ######################################################################
  65. # more procedures:
  66.  
  67. proc mode:exmh:border { t } {
  68.   j:text:insert_string $t \
  69.     "     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"
  70. }
  71.  
  72. # delete the signature if it exists (and is tagged so):
  73.  
  74. proc mode:exmh:delete_sig { t } {
  75.   catch {
  76.     $t delete sig.first end
  77.   }
  78. }
  79.  
  80. proc mode:exmh:insert_sig { t } {
  81.   global env
  82.   mode:exmh:delete_sig $t
  83.   set end [$t index end]
  84.   $t insert end "\n"
  85.   $t insert end [exec cat $env(HOME)/.signature]
  86.   $t insert end "\n"
  87.   $t tag add sig $end end
  88. }
  89.  
  90. proc mode:exmh:start_reply { t } {
  91.   set reply [exec cat "@" | sed {1,/^$/d} | \
  92.     sed {s/^>/  /} | sed {s/^/  /}]
  93.   $t insert end $reply
  94. }
  95.  
  96. proc mode:exmh:whom { t } {
  97.   jedit:cmd:save $t
  98.   set filename [jedit:get_filename $t]
  99.   j:more -height 10 -width 60 -title "Recipients" \
  100.     -text [exec whom -check $filename]
  101. }
  102.  
  103. proc mode:exmh:to_body { t } {
  104.   $t mark set insert end
  105.   $t yview -pickplace insert
  106. }
  107.  
  108. # BUG - doesn't handle multi-line headers.
  109.  
  110. proc mode:exmh:next_header { t } {
  111.   if [$t compare header.last <= insert] {
  112.     $t mark set insert 1.0
  113.   }
  114.   
  115.   set headpart [$t get insert header.last]
  116.   
  117.   set regex [format {(^|%s)[A-Za-z-]*:[ %s]*} "\n" "\t"]
  118.   if [regexp -indices -- $regex $headpart indices] {
  119.     $t tag remove sel 1.0 end
  120.     set valuestart [expr [lindex $indices 1] + 1]
  121.     $t mark set hdrfrom "insert + $valuestart chars"
  122.     $t tag add sel hdrfrom {hdrfrom lineend}
  123.     $t mark set insert {hdrfrom lineend}
  124.     $t yview -pickplace insert
  125.   } else {
  126.     # assume we're in the last header field, so jump to body
  127.     mode:exmh:to_body $t
  128.   }
  129. }
  130.  
  131. ######################################################################
  132. # define the MH menu:
  133. ######################################################################
  134.  
  135. proc mode:exmh:mkmenu1 { menu t } {
  136.   menubutton $menu -text {MH} -menu $menu.m
  137.   
  138.   menu $menu.m
  139.   $menu.m add command -label {Start Reply} \
  140.     -accelerator {[2]} -command "
  141.     mode:exmh:start_reply $t
  142.   "
  143.   $menu.m add command -label {Sign Email} -command "
  144.     mode:exmh:insert_sig $t
  145.   "
  146.   $menu.m add command -label {List Recipients} \
  147.     -accelerator {[7]} -command "
  148.     mode:exmh:whom $t
  149.   "
  150.   $menu.m add command -label {Insert Border} \
  151.     -accelerator {[8]} -command "
  152.     mode:exmh:border $t
  153.   "
  154.   $menu.m add command -label {Done} -command "
  155.     jedit:cmd:done $t
  156.   "
  157.   
  158.   bind $t <Meta-Key-2> "mode:exmh:start_reply $t"
  159.   bind $t <Meta-Key-7> "mode:exmh:whom $t"
  160.   bind $t <Meta-Key-8> "mode:exmh:border $t"
  161. }
  162.  
  163. ######################################################################
  164. # define the button bar:
  165. ######################################################################
  166.  
  167. proc mode:exmh:mkbuttons { w t } {
  168.   j:buttonbar $w -pady 2 -buttons [format {
  169.     {done Done {jedit:cmd:done %s}}
  170.     {border {* * *} {mode:exmh:border %s}}
  171.     {whom Whom {mode:exmh:whom %s}}
  172.     {sign Sign {mode:exmh:insert_sig %s}}
  173.     {reply {@} {mode:exmh:start_reply %s}}
  174.   } $t $t $t $t $t]
  175.   return $w
  176. }
  177.  
  178.